package org.gfids.trivial.gui;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JPanel;

import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.HeadlessException;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

import org.gfids.trivial.model.Cuestion;

@SuppressWarnings("serial")
public class GuiUpload extends AbstractGui {

	private JPanel jContentPane = null;
	private JLabel jLabel = null;
	private JScrollPane jScrollPane = null;
	private JTextArea pregunta = null;
	private JLabel jLabel1 = null;
	private JLabel jLabel2 = null;
	private JLabel jLabel3 = null;
	private JLabel jLabel4 = null;
	private JTextField respuesta = null;
	private JTextField opcion1 = null;
	private JTextField opcion2 = null;
	private JTextField opcion3 = null;
	private JButton btSubir;

	/****************** CONSTRUCTORES **********************************/
	
	public GuiUpload() throws HeadlessException {
		// TODO Auto-generated constructor stub
		super();
		initialize();
	}

	public GuiUpload(GraphicsConfiguration gc) {
		super(gc);
		// TODO Auto-generated constructor stub
		initialize();
	}

	public GuiUpload(String title) throws HeadlessException {
		super(title);
		// TODO Auto-generated constructor stub
		initialize();
	}

	public GuiUpload(String title, GraphicsConfiguration gc) {
		super(title, gc);
		// TODO Auto-generated constructor stub
		initialize();
	}

	/******************************* METODOS ***************************/
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(761, 321);
		this.setPreferredSize(new Dimension(600, 400));
		this.setContentPane(getJContentPane());
		this.setTitle("Subir pregunta");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
			gridBagConstraints21.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints21.gridwidth = GridBagConstraints.REMAINDER;
			gridBagConstraints21.gridy = 6;
			gridBagConstraints21.gridx = 0;
			gridBagConstraints21.anchor = GridBagConstraints.SOUTH;
			gridBagConstraints21.weighty = 0.5;
			GridBagConstraints gridBagConstraints20 = new GridBagConstraints();
			gridBagConstraints20.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints20.gridy = 5;
			gridBagConstraints20.weightx = 1.0;
			gridBagConstraints20.gridx = 1;
			GridBagConstraints gridBagConstraints19 = new GridBagConstraints();
			gridBagConstraints19.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints19.gridy = 4;
			gridBagConstraints19.weightx = 1.0;
			gridBagConstraints19.gridx = 1;
			GridBagConstraints gridBagConstraints18 = new GridBagConstraints();
			gridBagConstraints18.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints18.gridy = 3;
			gridBagConstraints18.weightx = 1.0;
			gridBagConstraints18.gridx = 1;
			GridBagConstraints gridBagConstraints17 = new GridBagConstraints();
			gridBagConstraints17.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints17.gridy = 2;
			gridBagConstraints17.weightx = 1.0;
			gridBagConstraints17.gridx = 1;
			GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
			gridBagConstraints16.gridx = 0;
			gridBagConstraints16.gridy = 5;
			btSubir = new JButton("Subir pregunta");
			jLabel4 = new JLabel("Opción falsa 3:");
			GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
			gridBagConstraints15.gridx = 0;
			gridBagConstraints15.gridy = 4;
			jLabel3 = new JLabel("Opción falsa 2:");
			GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
			gridBagConstraints14.gridx = 0;
			gridBagConstraints14.gridy = 3;
			jLabel2 = new JLabel("Opción falsa 1:");
			GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
			gridBagConstraints13.gridx = 0;
			gridBagConstraints13.gridy = 2;
			jLabel1 = new JLabel("Respuesta correcta:");
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.fill = GridBagConstraints.BOTH;
			gridBagConstraints1.anchor = GridBagConstraints.NORTH;
			gridBagConstraints1.gridwidth = GridBagConstraints.REMAINDER;
			gridBagConstraints1.insets = new Insets(15,15,15,15);
			gridBagConstraints1.gridy = 1;
			gridBagConstraints1.weightx = 1.0;
			gridBagConstraints1.weighty = 1.0;
			gridBagConstraints1.gridx = 0;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			jLabel = new JLabel("Introduzca la pregunta a realizar:");
			jContentPane = new JPanel();
			jContentPane.setLayout(new GridBagLayout());
			jContentPane.add(jLabel, gridBagConstraints);
			jContentPane.add(getJScrollPane(), gridBagConstraints1);
			jContentPane.add(jLabel1, gridBagConstraints13);
			jContentPane.add(jLabel2, gridBagConstraints14);
			jContentPane.add(jLabel3, gridBagConstraints15);
			jContentPane.add(jLabel4, gridBagConstraints16);
			jContentPane.add(getRespuesta(), gridBagConstraints17);
			jContentPane.add(getOpcion1(), gridBagConstraints18);
			jContentPane.add(getOpcion2(), gridBagConstraints19);
			jContentPane.add(getOpcion3(), gridBagConstraints20);
			jContentPane.add(getBtSubir(), gridBagConstraints21);
		}
		return jContentPane;
	}

	/************************** GETTERS DE COMPONENTES **************************/

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setPreferredSize(new Dimension(250, 100));
			jScrollPane.setViewportView(getPregunta());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTextArea	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getPregunta() {
		if (pregunta == null) {
			pregunta = new JTextArea();
			pregunta.setText("");
		}
		return pregunta;
	}
	
	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getRespuesta() {
		if (respuesta == null) {
			respuesta = new JTextField();
			respuesta.setColumns(0);
		}
		return respuesta;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getOpcion1() {
		if (opcion1 == null) {
			opcion1 = new JTextField();
		}
		return opcion1;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getOpcion2() {
		if (opcion2 == null) {
			opcion2 = new JTextField();
		}
		return opcion2;
	}
	
	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getOpcion3() {
		if (opcion3 == null) {
			opcion3 = new JTextField();
		}
		return opcion3;
	}
	
	

	/**************************** MAIN **********************************/
	
	private JButton getBtSubir() {
		return btSubir;
	}

	/**
	 * @param args
	 */
	/*public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				GuiUpload thisClass = new GuiUpload();
				
			}
		});
	}*/

	@Override
	public Cuestion getNewCuestion() {
		return new Cuestion(this.getPregunta().getText(), 
						    this.getRespuesta().getText(),
						    this.getOpcion1().getText(),
						    this.getOpcion2().getText(),
						    this.getOpcion3().getText());
	}

	@Override
	public void addListener(ActionListener l) {
		btSubir.addActionListener(l);
	}
	
}
